﻿// -----------------------------------------------------------------------
// <copyright file="SlavicPluralRules.cs" company="Moveax, LLC">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.Pluralization.Core.LanguageRules
{
    using System;

    /// <summary>Language plural rules for: Belarusian, Bosnian, Croatian, Russian, Serbian, Serbo-Croatian, Ukrainian.</summary>
    internal class SlavicPluralRules : CommonPluralRules
    {
        public SlavicPluralRules(string languageCode)
            : base(languageCode)
        {
        }

        public override PluralCategory GetCategoryFor(int value)
        {
            int absValue = Math.Abs(value);

            int mod10 = absValue % 10;
            int mod100 = absValue % 100;
            var category = PluralCategory.Other;

            if (mod10 == 1 && mod100 != 11)
                category = PluralCategory.One;
            else if ((2 <= mod10 && mod10 <= 4) && !(12 <= mod100 && mod100 <= 14))
                category = PluralCategory.Few;
            else if (mod10 == 0 || (5 <= mod10 && mod10 <= 9) || (11 <= mod100 && mod100 <= 14))
                category = PluralCategory.Many;

            return category;
        }
    }
}